package ControlLayer;
import java.util.ArrayList;

import ModelLayer.*; //import all Class' in ModelLayer

/**
 * Controller class for the address book
 * 
 * @author (kbh) 
 * @version (2005.03.31)
 * (FEN): 2006.03.21: Some changes to the architecture in order to assure layering
 *                    and loose coupling
 */
public class AddressBookCtr
{

    //declare instance variables to reference containers
    private AddressBookContainer abCon;
    private static AddressBookCtr instance;

    private AddressBookCtr()
    {
        abCon = AddressBookContainer.getInstance();

    }
    
    public static AddressBookCtr getInstance()
    {
        if(instance == null)
        {
            instance = new AddressBookCtr();
        }
        return instance;
    }
    
    public void addPerson(long id, String name, String address, int postalCode, String city, int phone)
    {   
        Person person = new Person(id, name, address, postalCode, city, phone);
        abCon.addPerson(person);
    }

    //Dummy implementation: after implementing the model layer 
    //objects of class Person are to be returned, not String
    public Person getPerson(long id)
    {
        Person person = null;
        person = abCon.getPerson(id);
        return person;

        

        //this method is to search the container for a person
        //with an id-number equal to the parameter id
        //when person is found, the method is to call print-methods in the TUI layer

    }

    public void updatePerson(long id1, long id, String name, String address, int postalCode, String city, int phone)
    {
        abCon.UpdatePerson(id1, id, name, address, postalCode, city, phone);
    }

    public void deletePerson(long id)
    {
        //search for the person and delete the object from the container
        abCon.deletePerson(id);
    }

    public void listAllPersons()
    {
        abCon.listAllPerson();
    }
    
    public int getSize()
    {
       return abCon.getSize();
    }
}
